package Day4.ZuoYe;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

//3：比较ArrayList和Vector的区别
public class ZuoYe3 {
    public static void main(String[] args) {
        List<Object> m=new ArrayList<>();
        List<Object>n=new Vector<>();
        int t = 10000000, c = 100;
        long a = System.nanoTime();
        for (int i = 0; i < t; m.add((int) (Math.random() * t)), i++) ;
        System.out.println("个数：" + m.size());
        for (int i = 0; i < c; i++) {
            int d = (int) (Math.random() * t);
            System.out.print( m.remove(d)+" ");
        }
        System.out.println();
        System.out.println("剩余个数：" + m.size());
        long a1 = System.nanoTime();
        long b = System.nanoTime();
        for (int i = 0; i < t; n.add((int) (Math.random() * t)), i++) ;
        System.out.println("个数：" + n.size());
        for (int i = 0; i < c; i++) {
            int d = (int) (Math.random() * t);
            System.out.print(n.remove(d)+" ");
        }
        System.out.println();
        System.out.println("剩余个数：" + n.size());
        long b1 = System.nanoTime();
        long mTime = a1 - a;
        long tTime = b1 - b;
        System.out.println("ArrayList的运行时间是" + mTime + "纳秒。");
        System.out.println("Vector的运行时间是" + tTime + "纳秒。");
        if (mTime > tTime) {
            System.out.println("Vector快！");
        } else if (mTime == tTime) {
            System.out.println("一样快！");

        } else {
            System.out.println("ArrayList快！");
        }
    }
}
